﻿using Alimentador.Foods;
using Alimentador.RightGroup.Results;
using System.Windows;
using System.Windows.Media;

namespace Alimentador.CustomControls
{
    /// <summary>
    /// Interaction logic for FoodListingPopup.xaml
    /// </summary>
    public partial class FoodListingPopup : Window
    {
        /// <summary>
        /// Initial Title string
        /// </summary>
        private string baseTitle = "Ficha Nutricional";

        /// <summary>
        /// Constructor
        /// </summary>
        public FoodListingPopup()
        {
            InitializeComponent();

            this.Title = baseTitle;
        }

        /// <summary>
        /// Load food properties and values to list view
        /// </summary>
        /// <param name="food">Food</param>
        public void FillListView(Food food)
        {
            FoodListingTitle.Content = "\"" + food.GetName + "\"";
            FoodListView.Items.Clear();
        
            foreach (FoodProperty prop in food.PropertyList)
            {
                if (prop.PropertyName == PropertyName.Percentagem || prop.PropertyName == PropertyName.Ficha || prop.PropertyName == PropertyName.Porcao)
                {
                    continue;
                }

                ResultItem res = new ResultItem();
                res.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
                res.Tag = prop;
                res.CollapseRecomended = false;
                res.NameLbl.Width = 300;
                res.ObtainedTxtBox.MaxLength = 8;
                res.ObtainedTxtBox.BorderThickness = new Thickness(0);
                res.ObtainedTxtBoxText = prop.Quantity.ToString("F2");
                res.SetNameLblContent = prop.GetPropertyName;
                res.UnitLblContent = FoodProperty.SetUnitByPropertyName(prop.PropertyName);
                FoodListView.Items.Add(res);
            }
        }

        /// <summary>
        /// Close this popup window
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CloseBtn_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
